package com.easy.project.controller.common;

import com.easy.project.base.result.BizResult;
import com.easy.project.domain.dto.common.SysFileDTO;
import com.easy.project.domain.vo.common.SysFileVO;
import com.easy.project.service.common.ISysFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  公用文件上传控制器
 * </p>
 *
 * @author wxz
 * @since 2023-11-09
 */
@RestController
@RequestMapping("/common/file")
@Api(tags = "公用文件控制器")
public class FileController {

    @Resource(name = "sysFileServiceImpl")
    private ISysFileService fileService;

    @PostMapping("/upload")
    @ApiOperation(value = "上传文件")
    public BizResult<SysFileVO> upload(MultipartFile file){
        return BizResult.success(fileService.upload(file));
    }

    @PostMapping("/get/file/list")
    @ApiOperation(value = "根据文件的唯一值获取文件信息")
    public BizResult<List<SysFileVO>> getUrlList(@Validated @RequestBody SysFileDTO sysFileDTO){
        return null;
    }

    @GetMapping("/download")
    @ApiOperation(value = "根据文件的唯一值下载文件")
    public void download(@RequestParam String fileKey, HttpServletResponse response){
        fileService.download(fileKey,response);
    }

}
